package com.example.drawboard.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import com.example.drawboard.R;
import com.example.drawboard.activity.MainActivity;

import java.util.ArrayList;
import java.util.List;

public class colorAdapter extends BaseAdapter {
    List<String> colors = new ArrayList<>();
    Context context;

    public colorAdapter(Context context,List<String> colors) {
        this.colors = colors;
        this.context = context;
    }

    @Override
    public int getCount() {
        return colors.size();
    }

    @Override
    public Object getItem(int i) {
        return colors.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        View views = LayoutInflater.from(context).inflate(R.layout.color_item,null);
        ImageView imageView = views.findViewById(R.id.iv_color);
        imageView.setBackgroundColor(Color.parseColor(colors.get(i)));
        if(i == MainActivity.index){
            imageView.setImageResource(R.drawable.yes);
        }else {
            imageView.setImageDrawable(null);
        }
        return views;
    }
}
